#include "bsp_can.h"
#include "main.h"

extern FDCAN_HandleTypeDef hfdcan1;

void can_filter_init(void)
{
	FDCAN_FilterTypeDef fdcan_filter;
	
	fdcan_filter.IdType = FDCAN_STANDARD_ID;                      //标准ID
	fdcan_filter.FilterIndex = 0;                                 //滤波器索引                   
	fdcan_filter.FilterType = FDCAN_FILTER_RANGE;                 //允许接收两个ID
	fdcan_filter.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;          //过滤器0关联到FIFO0  
	fdcan_filter.FilterID1 = 0x000;                               //32位ID//接收ID1
	fdcan_filter.FilterID2 = 0x7FF;                               //接收ID2
	HAL_FDCAN_ConfigFilter(&hfdcan1,&fdcan_filter); 		 	  
	HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE);
	HAL_FDCAN_ConfigFifoWatermark(&hfdcan1, FDCAN_CFG_RX_FIFO0, 1);
}

void bsp_can_init(void)
{
	can_filter_init();
	HAL_FDCAN_Start(&hfdcan1);                               //开启FDCAN
//	HAL_FDCAN_Start(&hfdcan2);
//	HAL_FDCAN_Start(&hfdcan3);
	HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0);
//	HAL_FDCAN_ActivateNotification(&hfdcan2, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0);
//	HAL_FDCAN_ActivateNotification(&hfdcan3, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0);
}

